SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.[DnnProduct_vw_PortalsDefaultLanguage]
AS
	SELECT DISTINCT 
        P.PortalID, 
		P.PortalGroupID, 
		PL.PortalName, 
		PL.LogoFile, 
		PL.FooterText, 
		P.ExpiryDate, 
		P.UserRegistration, 
		P.BannerAdvertising, 
		P.AdministratorId, 
		P.Currency, 
		P.HostFee, 
        P.HostSpace, 
		P.PageQuota, 
		P.UserQuota, 
		P.AdministratorRoleId, 
		P.RegisteredRoleId, 
		PL.Description, 
		PL.KeyWords, 
		PL.BackgroundFile, 
		P.GUID, 
		P.PaymentProcessor,
        P.ProcessorUserId, 
		P.ProcessorPassword, 
		P.SiteLogHistory, 
		U.Email, 
		P.DefaultLanguage, 
		P.TimezoneOffset, 
		PL.AdminTabId, 
		P.HomeDirectory, 
		PL.SplashTabId, 
        PL.HomeTabId, 
		PL.LoginTabId, 
		PL.RegisterTabId, 
		PL.UserTabId, 
		PL.SearchTabId,
        (SELECT     TOP (1) TabID
			FROM          dbo.DnnProduct_Tabs
				WHERE      (PortalID IS NULL) AND (ParentId IS NULL))
			AS SuperTabId, 
		P.CreatedByUserID, 
		P.CreatedOnDate, 
		P.LastModifiedByUserID, 
		P.LastModifiedOnDate, 
        PL.CultureCode
	FROM	dbo.DnnProduct_Portals AS P 
		INNER JOIN (SELECT  
						PortalID, 
						PortalName, 
						CASE WHEN LEFT(LOWER(LogoFile), 7) = 'fileid=' THEN
								(SELECT Folder + FileName
									FROM dbo.DnnProduct_Files
									WHERE fileid = CAST((RIGHT(LOWER(LogoFile), LEN(LogoFile) - 7)) AS INT)) 
							ELSE 
								LogoFile
							END AS LogoFile,
						FooterText, 
						Description, 
						KeyWords, 
                        CASE WHEN LEFT(LOWER(BackgroundFile), 7) = 'fileid=' THEN
								(SELECT Folder + FileName
									FROM dbo.DnnProduct_Files
									WHERE fileid = CAST((RIGHT(LOWER(BackgroundFile), LEN(BackgroundFile) - 7)) AS INT)) 
							ELSE 
								BackgroundFile 
							END AS BackgroundFile, 
						AdminTabId, 
						SplashTabId, 
						HomeTabId, 
						LoginTabId, 
						RegisterTabId, 
						UserTabId, 
						SearchTabId, 
						CultureCode
				FROM    dbo.DnnProduct_PortalLocalization) 
			AS PL ON P.PortalID = PL.PortalID AND PL.CultureCode = P.DefaultLanguage 
		LEFT OUTER JOIN dbo.DnnProduct_Users AS U ON P.AdministratorId = U.UserID
GO
